package com.zh.note.huawei.twohundred.打印任务排序;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String inputStr = scanner.nextLine();

        String[] numStrings = inputStr.split(",");
        int[] nums = new int[numStrings.length];
        for (int i = 0; i < numStrings.length; i++) {
            nums[i] = Integer.parseInt(numStrings[i]);
        }

        List<Map.Entry<Integer, Integer>> numsList = new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            numsList.add(new AbstractMap.SimpleEntry<>(i, nums[i]));
        }

        Deque<Map.Entry<Integer, Integer>> queue = new LinkedList<>(numsList);

        List<Map.Entry<Integer, Integer>> ans = new ArrayList<>();
        int count = 0;
        while (queue.size() > 1) {
            Map.Entry<Integer, Integer> task = queue.pollFirst();
            Map.Entry<Integer, Integer> curMax = Collections.max(queue, Comparator.comparingInt(Map.Entry::getValue));
            if (task.getValue() >= curMax.getValue()) {
                ans.add(new AbstractMap.SimpleEntry<>(task.getKey(), count));
                count++;
            } else {
                queue.addLast(task);
            }
        }
        // 此时队列里面只剩1个，且优先级最小的
        ans.add(new AbstractMap.SimpleEntry<>(queue.getFirst().getKey(), count));

        ans.sort(Comparator.comparingInt(Map.Entry::getKey));

        for (int i = 0; i < ans.size(); i++) {
            System.out.print(ans.get(i).getValue());
            if (i != ans.size() - 1) {
                System.out.print(",");
            }
        }
    }
}

